﻿var _bannercurrent = 0;
var _bannercount = 0;
var _autotimer;
$(function () {

    setupBanner();

    $("#tabs").tabs();

    topmenu();
});

function setupBanner() {

    _bannercount = $("#homebanner li").length;

    var nav = "<div id='homebannernav'><ul>";
    for (var i = 1; i <= _bannercount; i++) {
        nav += "<li></li>";
    }
    nav += "</ul></div><div class='clear'></div>";

    $("#homebanner").after(nav);

    $("#homebanner li").click(function () {
        clearInterval(_autotimer);
    });

    $("#homebannernav li").click(function () {
        clearInterval(_autotimer);
        var i = $("#homebannernav li").index($(this));
        _bannercurrent = i;
        rotateBanner();
    });

    if (_bannercount == 1) {
        rotateBanner();
    } else {
        rotateBanner();
        _autotimer = setInterval("rotateBanner();", 5000);
    }
}

function rotateBanner() {
    _bannercurrent++;
    if (_bannercurrent > _bannercount) {
        _bannercurrent = 1;
    }

    $("#homebanner li").stop(true, true).fadeOut(3000);
    $("#homebanner li:eq(" + (_bannercurrent - 1) + ")").stop(true, true).fadeIn(1000);
    $("#homebannernav li").removeClass("active");
    $("#homebannernav li:eq(" + (_bannercurrent - 1) + ")").addClass("active");
}

function topmenu() {
    //$(" #topnav ul ul").css({ display: "none" }); // Opera Fix
    $(" #topnav li").hover(function () {
        $(this).find('ul:first').css({ visibility: "visible", display: "none" }).show(400);
    }, function () {
        $(this).find('ul:first').css({ visibility: "hidden" });
    });
}